[IA64] fix ia64 linux domain builder broken by 12009:4a320d26fc24 of xen-unstable.hg.
authorawilliam@xenbuild.aw <awilliam@xenbuild.aw>
Fri, 10 Nov 2006 18:14:26 +0000 (11:14 -0700)
committerawilliam@xenbuild.aw <awilliam@xenbuild.aw>
Fri, 10 Nov 2006 18:14:26 +0000 (11:14 -0700)
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
tools/libxc/xc_linux_build.c

index af9a63cceddfffb6c2acb8cc791543609092606d..b16497b1b33c41293663ee0b6491b7b378e34490 100644 (file)
@@ -496,18 +496,10 @@ static int setup_guest(int xc_handle,
     if ( rc != 0 )
         goto error_out;
 
-    dsi.v_start = round_pgdown(dsi.v_start);
-    (load_funcs.loadimage)(image, image_size, xc_handle, dom, page_array,
-                           &dsi);
-
-    vinitrd_start = round_pgup(dsi.v_end);
-    if ( load_initrd(xc_handle, dom, initrd,
-                     vinitrd_start - dsi.v_start, page_array) )
-        goto error_out;
-
-    vinitrd_end    = vinitrd_start + initrd->len;
-    v_end          = round_pgup(vinitrd_end);
+    dsi.v_start    = round_pgdown(dsi.v_start);
+    vinitrd_start  = round_pgup(dsi.v_end);
     start_info_mpa = (nr_pages - 3) << PAGE_SHIFT;
+    *pvke          = dsi.v_kernentry;
 
     /* Build firmware.  */
     memset(&domctl.u.arch_setup, 0, sizeof(domctl.u.arch_setup));
@@ -519,21 +511,44 @@ static int setup_guest(int xc_handle,
     if ( xc_domctl(xc_handle, &domctl) )
         goto error_out;
 
-    start_page = dsi.v_start >> PAGE_SHIFT;
-    pgnr = (v_end - dsi.v_start) >> PAGE_SHIFT;
-    if ( (page_array = malloc(pgnr * sizeof(xen_pfn_t))) == NULL )
+    if ( (page_array = malloc(nr_pages * sizeof(xen_pfn_t))) == NULL )
     {
         PERROR("Could not allocate memory");
         goto error_out;
     }
 
+    start_page = dsi.v_start >> PAGE_SHIFT;
     if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array,
-                              start_page, pgnr) != pgnr )
+                              start_page, nr_pages) != nr_pages )
     {
         PERROR("Could not get the page frame list");
         goto error_out;
     }
 
+    /* in order to get initrd->len, we need to load initrd image at first */
+    if ( load_initrd(xc_handle, dom, initrd,
+                     vinitrd_start - dsi.v_start, page_array) )
+        goto error_out;
+
+    vinitrd_end    = vinitrd_start + initrd->len;
+    v_end          = round_pgup(vinitrd_end);
+    pgnr = (v_end - dsi.v_start) >> PAGE_SHIFT;
+    if ( pgnr > nr_pages )
+    {
+        free(page_array);
+        if ( (page_array = malloc(pgnr * sizeof(xen_pfn_t))) == NULL )
+        {
+            PERROR("Could not reallocate memory");
+            goto error_out;
+        }
+        if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array,
+                                  start_page, pgnr) != pgnr )
+        {
+                PERROR("Could not get the page frame list");
+                goto error_out;
+        }
+    }
+
     IPRINTF("VIRTUAL MEMORY ARRANGEMENT:\n"
            " Loaded kernel: %p->%p\n"
            " Init. ramdisk: %p->%p\n"
@@ -543,7 +558,8 @@ static int setup_guest(int xc_handle,
            _p(dsi.v_start),     _p(v_end));
     IPRINTF(" ENTRY ADDRESS: %p\n", _p(dsi.v_kernentry));
 
-    *pvke = dsi.v_kernentry;
+    (load_funcs.loadimage)(image, image_size, xc_handle, dom, page_array,
+                           &dsi);
 
     /* Now need to retrieve machine pfn for system pages:
      *  start_info/store/console